    <?php

class CategoriesController extends AppController {

var $name = 'Categories';
var $helpers = array('Html', 'Javascript');
var $components = array('Auth');

var $name2 = 'Fichiers';
  var $paginate = array(
        'limit' => 3,
        'order' => array(
            'Fichier.id' => 'desc'
        ));
     function beforeFilter(){
          parent::beforeFilter();
        $this->Auth->userModel = 'admin';
        $this->Auth->fields = array('username' => 'user', 'password' => 'mot-passe');
        $this->Auth->loginAction = array('controller' => 'admins', 'action' => 'login');
        $this->Auth->loginRedirect = array('controller' => 'pages', 'action' => 'display', 'home');
        $this->Auth->logoutRedirect = array('controller' => 'pages', 'action' => 'display', 'home');
         $this->Auth->allow('rechercher_categorie');
    }

    function ajouter_categorie() {

         
    

        if (!empty($this->data)) {

            
            if ($this->Category->save($this->data)) {
                $this->Session->setFlash('Catégorie Ajoutée');
                $this->redirect(array('action' => 'ajouter_categorie'));
            }
        }
    }


    function effacer_categorie(){

      $this->set('categories', $this->Category->find('all'));
    }


      function effacer_categorie_final($id_categorie) {
        $this->Category->id = $id_categorie;
        $this->Category->id;
        $this->set('categories', $this->Category->read());
    }


       function effacer_categorie_completo(){
        $form=$this->data;
        $id=$form['Category']['id'];
            if (!empty($this->data)) {
                 $this->loadModel('CategoriesFichier');
                $this->CategoriesFichier->deleteAll(array("CategoriesFichier.categorie_id" =>$id));
             
                if ($this->Category->delete($id)) {


                    $this->Session->setFlash('Categorie effacé.');
                $this->redirect(array('action' => 'effacer_categorie'));
                    }
                }

        }

        
        
        
      function liste_editer_categorie(){

         $this->set('categories', $this->Category->find('all'));


     }

      function modifier_categorie_final($id_categorie){

        $this->Category->id = $id_categorie;
        $this->Category->id;
        $this->set('categories', $this->Category->read());


     }

     function modifier_complete_categorie() {


        $form = $this->data;
   


	if (empty($this->data)==false) {
		//print_r ($this->data);

		//$this->Fichier->id = $id_art;
		$resultat = $this->Category->save($form);

	if ($resultat) {
			 echo "<script> alert('Categorie Modifie');</script>";

                echo "<script lenguage='javascript'>";
                echo "location='liste_editer_categorie'";
                echo "</script>";
		}
            }

         }


      function rechercher_categorie(){

           if (empty($this->data)) {
            $this->loadModel('Fichier');
            $this->set('fichiers', $this->Fichier->find('all'));

            //echo $id_cate=  $this->Category->id ;
        


           $form = $this->data;
           debug($form);
          // $this->set('categories', $this->Category->find('all'));
            $this->set('categories',  $this->Category->read());
           }

     }





}
?>
